<link href="Style.css" rel="stylesheet" type="text/css" />
<?php
session_start(); 

require("sql_functions.php");

if(isset($_SESSION['user']))
{

	$user = $_SESSION['user'];
	
	if(isset($_GET['projectID'])) 
	{ 	
		$pid = $_GET['projectID'];
		$project = sql_getProject($pid);

		
		if($project == -1)
		{
			echo "Invalid Project";
		}

		else
		{		
			$pTitle = $project["Title"];
			$pDesc = $project["Description"];
			$pManager = $project["ManagerEmail"];
			$employee = sql_getEmployee($pManager);
			$firstName = $employee['FirstName'];
			$lastName = $employee['LastName'];
			
			$ms = sql_getProjectMilestones($pid);	

			echo "<html>"; 
			echo "<head>"; 
			echo "</head>"; 
			echo "<body>";
			echo "<p> Project Milestones"; 
			echo "<p>Project: $pTitle ($pid)";
			echo "<p>Project Manager: $firstName $lastName";
			echo "<p>Description: $pDesc";
			echo "<p>Milestones";

			
			echo "<table border='1'>";	
			echo "<tr><td>Status</td><td>Name</td><td>Total Tasks</td><td>Active Tasks</td>";
			while($row = mysql_fetch_array($ms))
			{		
				$msDueDate = makePHPDate($row['DueDate']);
				$msName = $row['Name'];
				$msTasks = sql_getMilestoneTasks($pid, $msName);
				
        $total = 0;
        $active = 0;
        while($msTask = mysql_fetch_array($msTasks))
        {
          $total = $total + 1;
          if(!$msTasks['IsClosed'])
          {
            $active = $active + 1;
          }
        }

				echo "<tr><td>";
				echo "$msDueDate";
				echo "</td><td>";
				echo "<a href=\"milestone_info.php?projectID=$pid&MilestoneName=$msName\">$msName</a>";
				echo "</td><td>";
				echo "$total";
				echo "</td><td>";
				echo "$active";
				echo "</td></tr>";
			}
			echo "</table>";
			

			echo "<form action=\"milestone_info.php\" method=\"POST\">"; 
			echo "<input type=\"hidden\" name=\"projectID\" value=\"$pid\">";
			echo "<p><input type=\"submit\" name=\"save\" value=\"New Milestone\" />"; 
			echo "</form>"; 
  
			echo "<a href=\"dashboard.php\">Dashboard</a>";
			echo "<p><a href=\"project_info.php?projectID=$pid\">Project Info</a>";
  
			echo "</body>"; 
			echo "</html>"; 			
		}
		
	}

	else
	{
		echo "Invalid Project";
	}	
	
		
}
else
{
	echo "Must be logged in to view this page.";
}

?>
